package com.hm.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
* @Description: TODO
* @param 
* @return 
* @throws
* @author Coder编程
* @date 2021/6/17 13:05
*/
@Service
public class RedisTemplateOps<T> {

    @Autowired
    private RedisTemplate<String, T> redisTemplate;

    public RedisTemplate<String, T> getRedisTemplate(){
        return this.redisTemplate;
    }

    public T get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public void set(String key, T value, Long timeout, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
    }

    public void set(String key, T value, Long timeout) {
        set(key, value, timeout, TimeUnit.MINUTES);
    }

    public Boolean del(String key) {
        return redisTemplate.delete(key);
    }

    public Boolean hasKey(String key) {
        return redisTemplate.hasKey(key);
    }

    public Long getExpire(String key) {
        return redisTemplate.getExpire(key);
    }

    public Long rightPush(String key, T value) {
        return redisTemplate.opsForList().rightPush(key, value);
    }

    public T rightPop(String key) {
        return redisTemplate.opsForList().rightPop(key);
    }

    public Long leftPush(String key, T value) {
        return redisTemplate.opsForList().leftPush(key, value);
    }

    public T leftPop(String key) {
        return redisTemplate.opsForList().leftPop(key);
    }

}
